﻿namespace Logic
{
    /// <summary>
    /// 需要回复的handle
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    public abstract class MessageHandle<T1,T2> where T1 : Message where T2 : Message
    {
        /// <summary>
        /// 需要发送并回复
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static async System.Threading.Tasks.Task<T2> Send(T1 msg)
        {
            var tcs= new System.Threading.Tasks.TaskCompletionSource<Message>();
            DemoService.Singleton.SendMsg(msg,tcs);
            var res= await tcs.Task;
            return res as T2;
            // 发送消息，等待消息回复。注册事件，然后销毁事件
            // DemoService.Singleton.AddListener(msg.MsgId,);
        }
    }
    /// <summary>
    /// 仅发送的handle
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    public abstract class MessageHandle<T1> where T1 : Message 
    {
        /// <summary>
        /// 仅发送，不进行回复
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public abstract void Call(T1 msg);
    }
}